package com.redribbon.droidnoise;

import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.widget.Button;
import android.widget.TextView;
import android.widget.Toast;

public class ClientOptions extends Activity {
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        
        setContentView(R.layout.client_1);
        
       	final Button c1_back_button = (Button) findViewById(R.id.client_1_back_button);
        c1_back_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	finish();
            }
        });
        
       	final Button c1_next_button = (Button) findViewById(R.id.client_1_listen_button);
        c1_next_button.setOnClickListener(new Button.OnClickListener() {
            public void onClick(View v) {
                // Perform action on click
            	try {
            		NoiseConstants.client_port_number = Integer.parseInt((((TextView)findViewById(R.id.client_1_port_field)).getText()).toString());
            		Intent startClient = new Intent(ClientOptions.this, ClientController.class);
            		startActivity(startClient);
            	} catch (NumberFormatException e) {
            		Log.e(getClass().getName(), "Bad port number", e);
            		showError("Bad port number");
            	}
            }
        });
	}
	
	private void showError(String msg) {
   		Toast.makeText(this, msg, Toast.LENGTH_SHORT);
   	}	
}
